home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex26.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  706 b   |  33 lines

  1. Program ex21;
  2.  
  3. { Program to demonstrate the TCollection.FirstThat method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M : PMyObject;
  9.     I : Longint;
  10.  
  11. Function CheckField (Dummy: Pointer;P : PMyObject) : Longint;
  12.  
  13. begin
  14.   If P^.GetField>56 then
  15.     Checkfield:=1
  16.   else
  17.     CheckField:=0;
  18. end;
  19.     
  20. begin
  21.   C:=New(PCollection,Init(100,10));
  22.   For I:=1 to 100 do
  23.     begin
  24.     M:=New(PMyObject,Init);
  25.     M^.SetField(I);
  26.     C^.Insert(M);
  27.     end;
  28.   Writeln ('Inserted ',C^.Count,' objects');
  29.   Writeln ('first one for which Field>56  has index (should be 56) : ',
  30.             C^.IndexOf(C^.FirstThat(@CheckField)));
  31.   C^.FreeAll;
  32.   Dispose(C,Done);
  33. end.